package com.ds.robot.assistant.controller;

import com.ds.robot.assistant.common.R;
import com.ds.robot.assistant.job.DutyNewJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@RestController
@RequestMapping("/duty")
@Slf4j
public class DutyController {

    @Resource
    private DutyNewJob dutyJob;

    /**
     * 测试今天的值班预先提醒情况
     */
    @RequestMapping("/testToday")
    public R testDuty() {
        dutyJob.executeTest();
        return R.ok().put("data", LocalDateTime.now().toString());
    }

    /**
     * 测试指定日期的值班预先提醒情况
     *
     * @param date
     * @return
     */
    @RequestMapping("/testPreTip")
    public R testPreTip(@RequestParam String date) {
        try {
            LocalDate localDate = LocalDate.parse(date);
            dutyJob.executePreTip(localDate);
        } catch (Exception e) {
            return R.error(400, "日期格式错误");
        }
        return R.ok().put("data", LocalDateTime.now().toString());
    }

}
